package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusVipUser;
import com.meida.module.bus.client.entity.VipType;
import com.meida.module.bus.provider.service.AppUserExtraService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


/***
 * @description: 会议列表
 * @date: 2022年-06月-30日  15:06:49
 * @author lidd
 */
@Component("busVipUserPageHandler")
public class BusVipUserPageHandler implements PageInterceptor<BusVipUser> {
    private static final Logger log = LogManager.getLogger(BusVipUserPageHandler.class);

    @Resource
    AppUserExtraService appUserExtraService;

    public BusVipUserPageHandler() {
    }


    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        cq.select(VipType.class, "vipName", "vipCode", "vipTypeId");
        //cq.select(AppUserExtra.class, "nickName", "fullName");
        //cq.createJoin(AppUserExtra.class).setJoinAlias("appUser").setMainField("userId").setJoinField("userId");

        cq.createJoin(VipType.class).setMainField("vipTypeId");
    }

    @Override
    public void complete(CriteriaQuery<BusVipUser> cq, List<EntityMap> result, EntityMap extra) {
        for (EntityMap vuser : result) {
            vuser.put("fullName", appUserExtraService.getById(vuser.getLong("userId")).getFullName());
        }
    }
}
